package someTestExcemple.ioStream;

import java.io.FileReader;
import java.io.Reader;

public class FileReaderTest {
    //文件字符输入流
    public static void main(String[] args) {
        test1();
        System.out.println("测试test2----");
        test2();
    }
    public static void test1(){
        try(
                Reader fileReader = new FileReader("src/main/java/someTestExcemple/ioStream/fileReaderTest1.txt");
                ) {
            int c; //记录每次读取的字符编号
            while ((c = fileReader.read()) != -1) {
                System.out.print((char)c); //相比System.out.println((char)c) 不会自动换行
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void test2(){
        try(
                Reader fileReader = new FileReader("src/main/java/someTestExcemple/ioStream/fileReaderTest1.txt");
                ) {
            char[] buffer = new char[6]; //每次读取6个字符
            int len;
            while ((len = fileReader.read(buffer)) != -1) {
                System.out.print(new String(buffer,0,len));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
